<?php
/**
 * 账单
 */
namespace App\Http\ControllersAdmin;

use App\Service\MemberCollectService;
use App\Validation\DeleteValidation;
use App\Validation\MemberCollectValidation;
use App\Validation\MemberCollectSearchValidation;

class MemberCollectController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new MemberCollectSearchValidation, $this->request->getJsonRawBody());

		$data = MemberCollectService::getSearch($raw);
		$count = MemberCollectService::getSearch($raw, TRUE);

        $d = [];
		foreach ($data as $value) {
			$value->json_content = json_decode($value->json_content);
			$d[] = $value;
		}

        $assign = [
            'total' => $count,
            'list'  => $d
        ];

		return $this->echoJson($assign);
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = MemberCollectService::getInfo($id);
		$data->json_content = json_decode($data->json_content);
		return $this->echoJson($data);
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = MemberCollectService::forever($raw->id);
		return $this->echoJson('ok');
	}
}